Ext.namespace("Ext.milan.pagejs.page_modulepermissionconfig");

Ext.milan.pagejs.page_modulepermissionconfig.save = function(formId)
{
	var formEle = $(formId);
	
	formEle.userIds.value = Ext.milan.pagejs.page_modulepermissionconfig.serilizedSelectValues(formEle.permissionUsers);
	//formEle.deptIds.value = Ext.milan.pagejs.page_modulepermissionconfig.serilizedSelectValues(formEle.permissionDepts);
	formEle.groupIds.value = Ext.milan.pagejs.page_modulepermissionconfig.serilizedSelectValues(formEle.permissionPriGroups);
	
	Milan.ajaxutility.formSubmit(
    {
        form: formEle.id,
        success: function(){
        	if(setModulePerWin&&setModulePerWin.closeDialog) setModulePerWin.closeDialog();
		}
    });
}

Ext.milan.pagejs.page_modulepermissionconfig.serilizedSelectValues = function(selectEle)
{
	var seilizedValue = "";
	for (var i=0;i<selectEle.length;i++)
	{
		seilizedValue += selectEle[i].value+",";			
	}
	
	if(seilizedValue.length>1)
	{
		seilizedValue = seilizedValue.substr(0,seilizedValue.length-1);
	}
	return seilizedValue;
}

Ext.milan.pagejs.page_modulepermissionconfig.selectuser = function(ele,str)
{
	var formEle = ele.form;
    var obj = eval("formEle."+str);
	
	new Milan.widget.Selector({
		orgType:"12",
		title:"选择用户",
		deptUrl:"dept/selectDept.do?",
		quickSelectUrl:"user/quickUser.do?",
		searchUrl:"user/searchUser.do?",
		isRecentEnable :false,
		isUpdateRecentEnable :false,
		isDeptSelEnable:false
	},
	true,
	{
		onSelectedCallBack : function(arr)
		{
		var m = 0;
		var userlength = obj.length;
		var userexist = false;
		if (arr != null) 
		{
			var arrTmp = new Array(arr.length);
			
			for (var i = 0; i < arr.length; i++) 
			{
			
				if (arrTmp != null && arrTmp.length > 0) 
				{
					for (var j = 0; j < arrTmp.length; j++) 
					{
						if (arr[i].id == arrTmp[j]) 
						{
							userexist = true;
							break;
						}
					}
					if (!userexist) 
					{
						arrTmp[m++] = arr[i].id;
					}
				}
				else 
				{
					arrTmp[m++] = arr[i].id;
				}
				
				for (var x = 0; x < userlength; x++) 
				{
					if (arr[i].id == obj[x].value) 
					{
						userexist = true;
						break;
					}
				}
				
				if (!userexist) 
				{
					var oOption = document.createElement("OPTION");
					oOption.text = arr[i].name;
					oOption.value = arr[i].id;
					obj.options.add(oOption);
				}
				userexist = false;
			}
		}
		Ext.milan.pagejs.page_modulepermissionconfig.display( str);
		
		}
	});
}

Ext.milan.pagejs.page_modulepermissionconfig.selectDept = function(ele,objId)
{
	var formEle = ele.form;
    var obj = eval("formEle."+objId);
	
	new Milan.widget.Selector({
		orgType:"32",
		title:"选择部门",
		deptUrl:"dept/selectDept.do?",
		quickSelectUrl:"dept/quickSelectDept.do?",
		searchUrl:"dept/selectDeptByDeptid.do?",
		isRecentEnable :false,
		isUpdateRecentEnable :false
	},
	true,
	{
		onSelectedCallBack : function(arr)
		{
					var m = 0;
		var userlength = obj.length;
		var userexist = false;
		if (arr != null) 
		{
			var arrTmp = new Array(arr.length);
			
			for (var i = 0; i < arr.length; i++) 
			{
			
				if (arrTmp != null && arrTmp.length > 0) 
				{
					for (var j = 0; j < arrTmp.length; j++) 
					{
						if (arr[i].id == arrTmp[j]) 
						{
							userexist = true;
							break;
						}
					}
					if (!userexist) 
					{
						arrTmp[m++] = arr[i].id;
					}
				}
				else 
				{
					arrTmp[m++] = arr[i].id;
				}
				
				for (var x = 0; x < userlength; x++) 
				{
					if (arr[i].id == obj[x].value) 
					{
						userexist = true;
						break;
					}
				}
				
				if (!userexist) 
				{
					var oOption = document.createElement("OPTION");
					oOption.text = arr[i].name;
					oOption.value = arr[i].id;
					obj.options.add(oOption);
				}
				userexist = false;
			}
		}
		Ext.milan.pagejs.page_modulepermissionconfig.display( objId);
		}
	});
}


Ext.milan.pagejs.page_modulepermissionconfig.selectPriGroup = function(ele,objId)
{
    Ext.milan.pagejs.page_modulepermissionconfig.selectPriGroupDialog = Milan.commonutils.createModelPop({
		url:"group/findAll.do",
		title:"选择权限组",
		width:400
	});	
	
}
Ext.milan.pagejs.page_modulepermissionconfig.closeDialog = function()
{
	Ext.milan.pagejs.page_modulepermissionconfig.selectPriGroupDialog.closeDialog();
}

Ext.milan.pagejs.page_modulepermissionconfig.selectPriGroup.callback = function(arr)
{
	var objId = "permissionPriGroups";
	var obj = $(objId);
	var m = 0;
	var userlength = obj.length;
	var userexist = false;
	if (arr != null) 
	{
		var arrTmp = new Array(arr.length);
		
		for (var i = 0; i < arr.length; i++) 
		{
		
			if (arrTmp != null && arrTmp.length > 0) 
			{
				for (var j = 0; j < arrTmp.length; j++) 
				{
					if (arr[i].id == arrTmp[j]) 
					{
						userexist = true;
						break;
					}
				}
				if (!userexist) 
				{
					arrTmp[m++] = arr[i].id;
				}
			}
			else 
			{
				arrTmp[m++] = arr[i].id;
			}
			
			for (var x = 0; x < userlength; x++) 
			{
				if (arr[i].id == obj[x].value) 
				{
					userexist = true;
					break;
				}
			}
			
			if (!userexist) 
			{
				var oOption = document.createElement("OPTION");
				oOption.text = arr[i].name;
				oOption.value = arr[i].id;
				obj.options.add(oOption);
			}
			userexist = false;
		}
	}
	Ext.milan.pagejs.page_modulepermissionconfig.display( objId);
}

Ext.milan.pagejs.page_modulepermissionconfig.deluser = function(ele,str)
{
	var formEle = ele.form;
     var obj = eval("formEle."+str);
	if (obj.selectedIndex>-1)
	{
		obj.remove(obj.selectedIndex);
		if (obj.length>0) obj.selectedIndex=0;
	}
	else
	{
		new Milan.widget.Dialog('提示信息',"请先选择选项!");
	}
	Ext.milan.pagejs.page_modulepermissionconfig.display(str);
}

Ext.milan.pagejs.page_modulepermissionconfig.display = function(str)
{
	var formEle =$("modulePermissionConfigFormId");
   if(str=="permissionUsers")
   {
       if (formEle.permissionUsers.length>0)
		{
			formEle.permissionUsers.style.display="";
			formEle.permissionUsers_DelBtn.style.display="";
			formEle.permissionUsers_ClearBtn.style.display="";
		}
		else
		{
			formEle.permissionUsers.style.display="none";
			formEle.permissionUsers_DelBtn.style.display="none";
			formEle.permissionUsers_ClearBtn.style.display="none";
		}
   }
	if(str=="permissionDepts")	
	{
		if (formEle.permissionDepts.length>0)
		{
			formEle.permissionDepts.style.display="";
			formEle.permissionDepts_DelBtn.style.display="";
			formEle.permissionDepts_ClearBtn.style.display="";
		}
		else
		{
			formEle.permissionDepts.style.display="none";
			formEle.permissionDepts_DelBtn.style.display="none";
			formEle.permissionDepts_ClearBtn.style.display="none";
		}
	}
	if(str=="permissionPriGroups")	
   {
		if (formEle.permissionPriGroups.length>0)
		{
			formEle.permissionPriGroups.style.display="";
			formEle.permissionPriGroups_DelBtn.style.display="";
			formEle.permissionPriGroups_ClearBtn.style.display="";
		}
		else
		{
			formEle.permissionPriGroups.style.display="none";
			formEle.permissionPriGroups_DelBtn.style.display="none";
			formEle.permissionPriGroups_ClearBtn.style.display="none";
		}
	}
};
Ext.milan.pagejs.page_modulepermissionconfig.clearOption=function(str){
	$(str).innerHTML="";
	Ext.milan.pagejs.page_modulepermissionconfig.display(str);
};